package com.onpositive.wikitemplate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;

import com.onpositive.data.units.Unit;

public class WikiTemplate {
	
	public static class TemplateProvidedPropertyMetadata{
		
		String name = null ;
		String actualName = null ;
		String inBodyDescription = null ;
		String description = null ;		
		HashSet<String> otherDescriptions = null ;
		HashSet<String> children = null ;
		HashSet<String> parents = null ;
		String type = null ;
		int directlyRenderable = 0 ;
		Unit primaryUnit = null ;
		
		public String getName() {
			return name;
		}
		public String getActualName() {
			return actualName;
		}
		public String getInBodyDescription() {
			return inBodyDescription;
		}
		public String getDescription() {
			return description;
		}
		public HashSet<String> getOtherDescriptions() {
			return otherDescriptions;
		}
		public HashSet<String> getChildren() {
			return children;
		}
		public HashSet<String> getParents() {
			return parents;
		}
		public String getType() {
			return type;
		}
		public int getDirectlyRenderable() {
			return directlyRenderable;
		}
		public Unit getPrimaryUnit() {
			return primaryUnit;
		}
	}
	
	public WikiTemplate( String name, String globalPath, Collection<String> globalPaths, Collection<String> localPaths )
	{
		super();
		this.name = name ;
		this.globalPath = globalPath ;
		this.globalSubPaths = new HashSet<String>(globalPaths) ;
		this.localPaths = new HashSet<String>(localPaths) ;
	}
	private String name ;
	private HashSet<String> globalSubPaths ;
	private HashSet<String> localPaths ;
	private String globalPath ;
	
	/*init on demand*/
	private HashMap<String,TemplateProvidedPropertyMetadata> propertyMap = new HashMap<String, WikiTemplate.TemplateProvidedPropertyMetadata>()  ;

	public HashMap<String, TemplateProvidedPropertyMetadata> getPropertyMap() {
		return propertyMap;
	}

	public void addMeta(TemplateProvidedPropertyMetadata meta) {
		
		propertyMap.put( meta.name, meta ) ;
		
	}	
	
	public ArrayList<TemplateProvidedPropertyMetadata> getPropertiesByActualName( String actualName ){
		
		ArrayList<TemplateProvidedPropertyMetadata> result = new ArrayList<WikiTemplate.TemplateProvidedPropertyMetadata>() ;
		for( TemplateProvidedPropertyMetadata meta : propertyMap.values() ){
			
			String an = meta.actualName;
			if( an != null && an.equals(actualName) )
				result.add( meta ) ;
		}
		
		return result.size() > 0 ? result : null ;
	}
	
	public TemplateProvidedPropertyMetadata getPropertyByName( String name ){
		return propertyMap.get(name) ;
	}

	public String getName() {
		return name;
	}
	
}
